package com.shf.controller;

import com.shf.domain.ResponseResult;
import com.shf.domain.entity.Article;
import com.shf.service.ArticleService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author 叶枫
 * @date 2023/10/26.
 * 文章控制层
 */
@RestController
/**添加父路径*/
@RequestMapping("/article/")
@Api(tags = "文章接口")
public class ArticleController {

    /**注入公共模块业务层*/
    @Autowired
    private ArticleService articleService;
    /*********************************测试mybatisPlus***************************/
    /**Article也是公共模块的*/
    @GetMapping("test")
    public List<Article> test(){
        return articleService.list();
    }

    /*************************************统一响应格式***********************************/

    @GetMapping("hotArticleList")
    public ResponseResult hotArticle(){
        ResponseResult result = articleService.hotArticleList();
        return result;
    }

    /**----------------------------------分页查询文章的列表---------------------------------*/

    @GetMapping("articleList")
    /**ResponseResult是huanf-framework工程的domain目录的类*/
    public ResponseResult articleList(Integer pageNum,Integer pageSize,Long categoryId){
        return articleService.articleList(pageNum,pageSize,categoryId);
    }

    /**-------------------------查询文章详细---------------------------------*/
    @GetMapping("{id}")
    public ResponseResult getArticleDetail(@PathVariable("id") Long id,
     HttpServletRequest request
    ){

        return articleService.getArticleDetail(id,request);
    }
    @PutMapping("/updateViewCount/{id}")
    public ResponseResult updateViewCount(@PathVariable("id") Long id){

        return articleService.updateViewCount(id);
    }

}
